# Contributor: Dominika Liberda <ja@sdomi.pl>
# Maintainer: Dominika Liberda <ja@sdomi.pl>
pkgname=yosys
pkgver=0.36
pkgrel=3
pkgdesc="Yosys Open SYnthesis Suite"
url="https://yosyshq.net"
# doesn't build
arch="all !s390x !riscv64"
license="ISC"
depends="
	abc
	"
makedepends="
	bash
	bison
	boost-dev
	clang
	flex
	gawk
	graphviz-dev
	libffi-dev
	lld
	protobuf-dev
	python3
	readline-dev
	tcl-dev
	zlib-dev
	"
subpackages="$pkgname-dev py3-$pkgname:py3:noarch"
source="https://github.com/YosysHQ/yosys/archive/refs/tags/yosys-$pkgver.tar.gz
	"
builddir="$srcdir/$pkgname-$pkgname-$pkgver/"
options="!check" # current yosys employee confirmed those dont work

build() {
	export CFLAGS="$CFLAGS -flto=thin"
	export CXXFLAGS="$CXXFLAGS -flto=thin"
	export LDFLAGS="$LDFLAGS -fuse-ld=lld"

	local pyver="$(python3 -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")')"

	cat > Makefile.conf <<- EOF
	CONFIG:=clang
	PREFIX:=/usr
	ABCEXTERNAL:=abc
	BOOST_PYTHON_LIB:=-lpython$pyver -lboost_python${pyver/./}
	ENABLE_LIBYOSYS:=1
	ENABLE_NDEBUG:=1
	ENABLE_PROTOBUF:=1
	ENABLE_PYOSYS:=1
	ENABLE_ABC:=1
	EOF

	make
}

package() {
	make DESTDIR="$pkgdir" install

	# link python to the global yosys
	ln -sfv /usr/lib/yosys/libyosys.so "$pkgdir"/usr/lib/python3*/site-packages/pyosys/libyosys.so
}

py3() {
	pkgdesc="$pkgdesc (python module)"
	depends="python3 $pkgname=$pkgver-r$pkgrel"

	amove usr/lib/python3*
}

sha512sums="
3d496ab7efba75b6a8e3ded30d62214e868c52b7f0609f214ea4a336dcb9e38343fc3ae0ddea18c026028989d4caee06efa3822210d8e88e159a3fca28fcae4e  yosys-0.36.tar.gz
"
